package com.work.blog.service;

import com.work.blog.mapper.BlogMapper;
import com.work.blog.model.BlogInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:DELL
 * Date:2025-06-16
 * Time:18:48
 */
@Slf4j
@Service
public class BlogService {
    @Autowired
    private BlogMapper blogMapper;

    public List<BlogInfo> getList() {
        return blogMapper.selectAll();
    }

    public BlogInfo getBlogDetail(Integer blogId) {
        return blogMapper.selectById(blogId);
    }

    public Boolean insertBook(BlogInfo blogInfo) {
        try {
            //插入一条数据才成功
            Integer result = blogMapper.insertBlog(blogInfo);
            if (result==1){
                return true;
            }
        }catch (Exception e){
            log.error("添加博客失败，e:",e);
        }
        return false;
    }

    public Boolean update(BlogInfo blogInfo) {
        try {
            Integer result = blogMapper.updateBlog(blogInfo);
            if (result==1){
                return true;
            }
        }catch (Exception e){
            log.error("删除博客失败，e",e);
        }
        return false;
    }
}
